package com.common.util;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.coursemanage.common.model.Course;

public class ExcelExport {

	   String[] excelHeader = { "学校", "课程"};    
	    public HSSFWorkbook export(List<Course> list,String schoolName) {    
	        HSSFWorkbook wb = new HSSFWorkbook();    
	        HSSFSheet sheet = wb.createSheet("Campaign");    
	        HSSFRow row = sheet.createRow((int) 0);    
	        HSSFCellStyle style = wb.createCellStyle();   
	    
	        for (int i = 0; i < excelHeader.length; i++) {    
	            HSSFCell cell = row.createCell(i);    
	            cell.setCellValue(excelHeader[i]); 
	            cell.setCellStyle(style); 
	            sheet.autoSizeColumn(i);  
	            sheet.setColumnWidth(i, 7800);  
	        }    
	    
	        for (int i = 0; i < list.size(); i++) {    
	            row = sheet.createRow(i + 1);    
	            Course student = list.get(i);    
	            row.createCell(0).setCellValue(schoolName);    
	            row.createCell(1).setCellValue(student.getName());    
	        }    
	        return wb;    
	    }   
}
